package thread;

public class Testsynchronized implements Runnable{
    static int i=5;
    @Override
    public  void run() {
        test1();
        //test2();
    }
    public synchronized void test1(){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("i="+i--);
    }
    public synchronized static void test2(){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("i="+i--);
    }

}
class A{
    public static void main(String[] args) {
        Testsynchronized t=new Testsynchronized();
        Thread t1= new Thread(t);
        Thread t2= new Thread(t);
        Thread t3= new Thread(t);
        Thread t4= new Thread(t);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
    class B {
        public static void main(String[] args) {
            //Testsynchronized t=new Testsynchronized();
            Thread t1 = new Thread(new Testsynchronized());
            Thread t2 = new Thread(new Testsynchronized());
            Thread t3 = new Thread(new Testsynchronized());
            Thread t4 = new Thread(new Testsynchronized());

            t1.start();
            t2.start();
            t3.start();
            t4.start();
        }

    }